class Solution {
public:
    vector<vector<int>> kClosest(vector<vector<int>>& points, int k) {
        struct cmp {
            bool operator()(vector<int>& a, vector<int>& b) {
                return pow(a[0], 2) + pow(a[1], 2) < pow(b[0], 2) + pow(b[1], 2);
            }
        };

        priority_queue<vector<int>, vector<vector<int>>, cmp>q;

        for (int i = 0; i < points.size(); i++) {
            q.push(points[i]);
            if(q.size()>k){
                q.pop();
            }
        }

        vector<vector<int>>answer;

        while(!q.empty()){
            answer.push_back(q.top());
            q.pop();
        }

        return answer;
    }
};